package com.liangchen.astools.memtracker

import android.os.Build
import android.os.Debug
import androidx.annotation.RequiresApi
import com.liangchen.astools.utils.AsLog.i

object Memtracker {
    @RequiresApi(api = Build.VERSION_CODES.M)
    fun trackMemoryOnce(): Map<String, String> {
        val memoryInfo = Debug.MemoryInfo()
        Debug.getMemoryInfo(memoryInfo)
        val statsMap = memoryInfo.memoryStats
        val sb = StringBuffer()
        sb.append("""
    java: ${statsMap["summary.java-heap"]}
    
    """.trimIndent())
        sb.append("""
    native:${statsMap["summary.native-heap"]}
    
    """.trimIndent())
        sb.append("""
    code: ${statsMap["summary.code"]}
    
    """.trimIndent())
        sb.append("""
    stack: ${statsMap["summary.stack"]}
    
    """.trimIndent())
        sb.append("""
    graphics: ${statsMap["summary.graphics"]}
    
    """.trimIndent())
        sb.append("""
    other: ${statsMap["summary.private-other"]}
    
    """.trimIndent())
        sb.append("""
    system: ${statsMap["summary.system"]}
    
    """.trimIndent())
        sb.append("""
    total:: ${statsMap["summary.total-pss"]}
    
    """.trimIndent())
        sb.append("""
    swap: ${statsMap["summary.total-swap"]}
    
    """.trimIndent())
        i("cdgaslog", sb.toString())
        return statsMap
    }
}